###
#Table D1: Electoral College Certification by District Characteristics
###

library(plyr)
library(xtable)

certification <- read.csv('certification-district.csv')
certification$vote <- ifelse(certification$rc10.arizona=="Yea"|certification$rc11.pennsylvania=="Yea", 1, 0)
certification$trump.share <- certification$trump.share/100
certification$vote.bin <- cut(x=certification$trump.share,breaks=c(0,.50,.55,.60,.65,.70,1))

decertify.table <- ddply(certification,.(vote.bin),summarise,share=mean(vote,na.rm=TRUE),total=length(vote))
xtable(decertify.table)